package cn.woflcode.game.model.util;




import javazoom.jl.player.Player;

import java.io.FileInputStream;


public class AudioPlayer extends Thread {
    private boolean loop = false;//是否需要循环播放
    private Player player;  //播放器

    public AudioPlayer(String fileName, boolean loop) {
        this.loop = loop;
        try {
            player = new Player(new FileInputStream(fileName));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    //播放
    public void run() {
        try {
            do{
                player.play();
            }while(loop);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    //停止
    public  void close(){
        this.loop = false;
        player.close();
        this.interrupt();
    }
}
